package com.frank.work;

import com.alibaba.excel.util.CollectionUtils;
import org.apache.commons.lang.StringUtils;

import javax.persistence.AttributeConverter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author 小石潭记
 * @date 2021/12/21 10:22
 * @Description: ${todo}
 */
public class SubTaskConverter implements AttributeConverter<List<String>, String> {

    @Override
    public String convertToDatabaseColumn(List<String> list) {
        if (CollectionUtils.isEmpty(list)) {
            return "";
        }
        return list.toString();
    }

    @Override
    public List<String> convertToEntityAttribute(String s) {
        if (StringUtils.isBlank(s)) {
            return new ArrayList<>();
        }
        String[] subTasks = s.split(",");
        return Arrays.asList(subTasks);
    }
}
